package com.ptmall.app.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.bean.ProductBean;
import com.ptmall.app.bean.ZtBean;
import com.ptmall.app.bean.ZtListBean;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.ui.adapter.HomePageReCommendAdapter;
import com.ptmall.app.ui.adapter.ZtAdapter;
import com.ptmall.app.utils.GlideUtil;
import com.ptmall.app.view.NoScrollListView;
import com.ptmall.app.view.TitleBarView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ZtActivity extends BaseMvpActivity {

    NoScrollListView zt_grid;
    TextView zt_name;
    ImageView zt_img;
    TitleBarView titlebar;


    String id,name,title;

    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    ZtAdapter mZtAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_zt);
    }

    @Override
    public void initViews() {
        zt_grid = (NoScrollListView) findViewById(R.id.zt_grid);
        zt_img = (ImageView) findViewById(R.id.zt_img);
        titlebar = (TitleBarView) findViewById(R.id.titlebar);
    }

    @Override
    public void initEvents() {
        id = getIntent().getStringExtra("id");
        title = getIntent().getStringExtra("title");
        titlebar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });
        titlebar.setText(title);
        getZtData();
    }

    private void getZtData(){
        Map map = new HashMap<String,String>();
        map.put("zhuanId",id);
        apiDataRepository.getZtData(map, new ApiNetResponse<ZtBean>() {
            @Override
            public void onSuccess(ZtBean data) {
                GlideUtil.showImg(getContext(),data.image_info,zt_img);
                showReCommend(data.list);
            }
        });
    }


    private void showReCommend(List<ZtListBean> list){
        mZtAdapter = new ZtAdapter(getContext(),list);
        zt_grid.setAdapter(mZtAdapter);

    }
}
